package main

import (
	"fmt"
	"time"
)

func main() {
	ch := make(chan int)    //用来进行数据通信的channel
	quit := make(chan bool) //用来判断是否退出的channel

	go func() {
		for i := 0; i <= 5; i++ {
			ch <- i
			time.Sleep(time.Second * 1)
		}
		close(ch)
		//quit <- true
		//runtime.Goexit()
	}()

	for {
		select {
		case num, ok := <-ch:
			if !ok {
				fmt.Println("ch channel已经关闭")
				return
			}
			fmt.Println("num=", num)
		case <-quit:
			//break //跳出select
			return
		}
	}
}
